package com.cyk.controller;

import com.cyk.entity.Blog;
import com.cyk.entity.vo.BlogVO;
import com.cyk.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("blog")
public class BlogController {

    @Autowired
    private BlogService blogService;

    @GetMapping("/{id}")
    public Blog blog(@PathVariable("id") Long id) {
        return blogService.queryById(id);
    }

    @PostMapping
    public String add(@RequestBody Blog blog) {
        blogService.insert(blog);
        return "ok";
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable("id") Long id) {
        blogService.deleteById(id);
        return "ok";
    }

    @PutMapping
    public String update(Blog blog) {
        blogService.update(blog);
        return "ok";
    }

    @GetMapping("/{blog_id}/{user_id}")
    public BlogVO blogAndUser(@PathVariable("blog_id") Long blogId,
                              @PathVariable("user_id") Long userId) {
        return blogService.getBlogAndUser(blogId, userId);
    }

}
